/*
// 实现禁止浏览器弹性效果
window.onload = function () {
  let [startX, startY] = [0, 0]
  // 需要响应touch 事件的容器添加 class="tu-need-scroll'即可
  const scrollBoxes = Array.from(document.querySelectorAll('.tu-need-scroll'))

  document.body.addEventListener('touchstart', (e) => {
    if (!scrollBoxes.length) { return }
    startX = e.touches[0].pageX
    startY = e.touches[0].pageY
  }, { passive: false })

  document.body.addEventListener('touchmove', (e) => {
    if (!scrollBoxes.length) { return e.preventDefault() }
    let node = isChildTarget(e.target, scrollBoxes)
    const moveX = e.touches[0].pageX
    const moveY = e.touches[0].pageY
    const top = node && node.scrollTop
    const ch = node && node.clientHeight
    const sh = node && node.scrollHeight

    const isVertical = Math.abs(moveY - startY) > Math.abs(moveX - startX)
    const isOnSide = (top === 0 && moveY > startY) || (top + ch === sh && moveY < startY)
    if (!node) {
      e.preventDefault()
    } else if (isVertical && isOnSide) {
      e.preventDefault()
    }
  }, { passive: false })
}

function isChildTarget(currTarget, scrollBoxes) {
  let parentNode = currTarget
  if (currTarget && scrollBoxes) {
    while (parentNode) {
      let node = scrollBoxes.find(el => el === parentNode)
      if (node) { return node }
      parentNode = parentNode.parentNode
    }
  }
  return null
}
*/

// 实现移动端换算1rem = 10px
var clientWidth = document.documentElement.clientWidth || document.body.clientWidth
if( clientWidth <= 750) {
  document.documentElement.style.fontSize = clientWidth / 37.5 + 'px' // 1rem = 10px
  // window.onload = function () { document.body.style.fontSize = '1.4rem' }
}

// 解决安卓输入框被键盘挡住问题
if (/Android/.test(navigator.appVersion)) {
  window.addEventListener('resize', function() {
    if (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA') {
      document.activeElement.scrollIntoView()
    }
  })
}

function getScrollTop() {
  var scrollTop=0;
  if(document.documentElement&&document.documentElement.scrollTop) {
    scrollTop=document.documentElement.scrollTop;
  } else if(document.body) {
    scrollTop=document.body.scrollTop;
  }
  return scrollTop;
}
